import {Request} from "../../utils/request";
import host from "../../utils/host";
const HostUrl = host.service;
const Requ = new Request();
var app = getApp();
var _orderid

Page({
  data: {
    
  },
  onLoad: function (options) {
      this.setData({
        navH: app.globalData.navHeight,
      })
      _orderid = options.orderid
  },
  onShow: function () {
      var that = this;
      new Request('get_user_addresslist.cls.php').request(
        () => {
          return {
            data: 1
          }
        },
      (res) => {
        that.setData({
            data: res.data
        })
      });
  },
  select_ad: function (e) {
      wx.showLoading({
          title: '正在提交',
          mask: true
      });
      new Request('update_order_address.cls.php').request(
        () => {
          return {
            orderid: _orderid,
              name: e.currentTarget.dataset.name,
              phone: e.currentTarget.dataset.phone,
              addressid: e.currentTarget.dataset.id
          }
        },
      (res) => {
        if (res.data.code == 1) {
            wx.showToast({
                title: res.data.msg,
                icon: 'success',
                duration: 2000,
                mask: true
            })

            setTimeout(function () {
                wx.navigateBack({
                    delta: 1
                })
            }, 2000)
        } else {
            wx.showToast({
                title: res.data.msg,
                icon: 'none',
                duration: 2000,
                mask: true
            })

            setTimeout(function () {
                wx.navigateBack({
                    delta: 1
                })
            }, 2000)
        }
      });
  },
  goback: function (e) {
    setTimeout(function () {
      wx.navigateBack({
        delta: 1
      })
    }, 20)
  },
})